package com.my.servlets;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class MobileServlet  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String mobile = (String) request.getParameter("mobile");
        System.out.println(mobile);
        PrintWriter out = response.getWriter();
        if("18892658512".equals(mobile)){
            //out.write("true");//Servlet以输出流的方式将信息返回给客户端
            out.write("{\"msg\":\"true\"}");//传递json格式
        }else{
            //out.write("false");
            out.write("{\"msg\":\"false\"}");
        }
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
